// Copyright (C) <2018> Zealcomm Inc.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef p2p_SignalingChannelProtocol_h
#define p2p_SignalingChannelProtocol_h
#import "IRTC/IRTCErrors.h"
@protocol IRTCP2PSignalingChannelDelegate;
/**
 @brief Protocol for signaling channel.<br>信令通道的协议。
 Developers may utilize their own signaling server by implementing this protocol.<br>开发者可以用他们自己的信令服务器来实现这个协议。
 */
RTC_EXPORT
@protocol IRTCP2PSignalingChannelProtocol<NSObject>
@optional
@property(nonatomic, weak) id<IRTCP2PSignalingChannelDelegate> delegate;
/**
 @brief Connect to the signaling server<br>连接到信令服务器。
 @param token A token used for connecting signaling server<br>用于连接信令服务器的令牌。
 */
- (void)connect:(NSString*)token
      onSuccess:(void (^)(NSString*))onSuccess
      onFailure:(void (^)(NSError*))onFailure;
/**
 @brief Send a message to a target client<br>给目标客户端发送消息。
 @param message Message needs to be send to signaling server<br>要发送给信令服务器的消息。
 @param targetId Target user's ID.<br>目标用户的ID。
 */
- (void)sendMessage:(NSString*)message
                 to:(NSString*)targetId
          onSuccess:(void (^)())onSuccess
          onFailure:(void (^)(NSError*))onFailure;
/**
 @brief Disconnect from signaling server.<br>从信令服务器断开连接。
 */
- (void)disconnectWithOnSuccess:(void (^)())onSuccess
                      onFailure:(void (^)(NSError*))onFailure;
@end
/**
 @brief Signaling channel will notify observer when event triggers.<br>当事件触发时，信令通道将通知观察者。
 */
@protocol IRTCP2PSignalingChannelDelegate<NSObject>
/**
 @brief This function will be triggered when new message arrives.<br>当新消息达到时这个函数将被触发。
 @param message Message received from signaling server.<br>从信令服务器收到的消息。
 @param senderId Sender's ID.<br>发送者的ID。
 */
- (void)channel:(id<IRTCP2PSignalingChannelProtocol>)channel
    didReceiveMessage:(NSString*)message
                 from:(NSString*)senderId;
/**
 @brief This function will be triggered when disconnected from signaling server.<br>当和信令服务器断开连接时这个函数将被触发。
 */
- (void)channelDidDisconnect:(id<IRTCP2PSignalingChannelProtocol>)channel;
@end
#endif
